***Election results

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\allwaves_new.dta"
keep if country == "Belgium"
save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\belgium.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\allwaves_new.dta"
keep if country == "Germany"
save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\germany.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\allwaves_new.dta"
keep if country == "Greece"
save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\greece.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\allwaves_new.dta"
keep if country == "Ireland"
save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\ireland.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\allwaves_new.dta"
keep if country == "Portugal"
save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\portugal.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\allwaves_new.dta"
keep if country == "Spain"
save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\spain.dta", replace

***Belgium

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\belgium.dta"

order country surveyname id 
keep if surveyname == "EB2" | surveyname == "MAPLE2"

keep country surveyname id voted_eu_EB party_voted_eu_EB voted_eu_MA votechoice_eu_MA

*Turnout

gen turnout_MA = .
replace turnout_MA = 0 if voted_eu_MA > 1 & voted_eu_MA != .
replace turnout_MA = 1 if voted_eu_MA == 1

gen turnout_EB = .
replace turnout_EB = 0 if voted_eu_EB > 1 & voted_eu_EB != .
replace turnout_EB = 1 if voted_eu_EB == 1

gen turnout_MA_b = (turnout_MA - 0.8847)
gen turnout_EB_b = (turnout_EB - 0.8847)

gen turnout_b = turnout_MA_b
replace turnout_b = turnout_EB_b if surveyname == "EB2"
label var turnout_b "Turnout"

sort surveyname
by surveyname: ci means turnout_b

***Parties

*Maple

gen vote_valid_MA = .
replace vote_valid_MA = 0 if votechoice_eu_MA <= 66

gen vote_nva_MA = vote_valid_MA
replace vote_nva_MA = 1 if votechoice_eu_MA == 6

gen vote_vb_MA = vote_valid_MA
replace vote_vb_MA = 1 if votechoice_eu_MA == 13

gen vote_cd_MA = vote_valid_MA
replace vote_cd_MA = 1 if votechoice_eu_MA == 1 | votechoice_eu_MA == 11

gen vote_so_MA = vote_valid_MA
replace vote_so_MA = 1 if votechoice_eu_MA == 5 | votechoice_eu_MA == 12

gen vote_gr_MA = vote_valid_MA
replace vote_gr_MA = 1 if votechoice_eu_MA == 2 | votechoice_eu_MA == 7

gen vote_li_MA = vote_valid_MA
replace vote_li_MA = 1 if votechoice_eu_MA == 4 | votechoice_eu_MA == 8

gen vote_rl_MA = vote_valid_MA
replace vote_rl_MA = 1 if votechoice_eu_MA == 10

gen vote_other_MA = vote_valid_MA
replace vote_other_MA = 1 if votechoice_eu_MA == 3 | votechoice_eu_MA == 9 | votechoice_eu_MA == 14 | votechoice_eu_MA == 66

*EB

gen vote_valid_EB = .
replace vote_valid_EB = 0 if party_voted_eu_EB <= 17

gen vote_nva_EB = vote_valid_EB
replace vote_nva_EB = 1 if party_voted_eu_EB == 1

gen vote_vb_EB = vote_valid_EB
replace vote_vb_EB = 1 if party_voted_eu_EB == 2

gen vote_cd_EB= vote_valid_EB
replace vote_cd_EB = 1 if party_voted_eu_EB == 5 | party_voted_eu_EB == 11

gen vote_so_EB = vote_valid_EB
replace vote_so_EB = 1 if party_voted_eu_EB == 3 | party_voted_eu_EB == 9

gen vote_gr_EB = vote_valid_EB
replace vote_gr_EB = 1 if party_voted_eu_EB == 6 | party_voted_eu_EB == 8

gen vote_li_EB = vote_valid_EB
replace vote_li_EB = 1 if party_voted_eu_EB == 4 | party_voted_eu_EB == 7

gen vote_rl_EB = vote_valid_EB
replace vote_rl_EB = 1 if party_voted_eu_EB == 10

gen vote_other_EB = vote_valid_EB
replace vote_other_EB = 1 if party_voted_eu_EB == 12 | party_voted_eu_EB == 13 | party_voted_eu_EB == 14 | party_voted_eu_EB == 15 | party_voted_eu_EB == 17


*Merge parties

gen vote_nva_MA_b = (vote_nva_MA - 0.1373)
gen vote_nva_EB_b = (vote_nva_EB - 0.1373)

gen vote_nva_b = vote_nva_MA_b
replace vote_nva_b = vote_nva_EB_b if surveyname == "EB2"
label var vote_nva_b "N-VA"

gen vote_vb_MA_b = (vote_vb_MA - 0.1168)
gen vote_vb_EB_b = (vote_vb_EB - 0.1168)

gen vote_vb_b = vote_vb_MA_b
replace vote_vb_b = vote_vb_EB_b if surveyname == "EB2"
label var vote_vb_b "Vlaams Belang"

gen vote_cd_MA_b = (vote_cd_MA - 0.1231)
gen vote_cd_EB_b = (vote_cd_EB - 0.1231)

gen vote_cd_b = vote_cd_MA_b
replace vote_cd_b = vote_cd_EB_b if surveyname == "EB2"
label var vote_cd_b "Christian democrats"

gen vote_so_MA_b = (vote_so_MA - 0.1644)
gen vote_so_EB_b = (vote_so_EB - 0.1644)

gen vote_so_b = vote_so_MA_b
replace vote_so_b = vote_so_EB_b if surveyname == "EB2"
label var vote_so_b "Socialists"

gen vote_li_MA_b = (vote_li_MA - 0.1712)
gen vote_li_EB_b = (vote_li_EB - 0.1712)

gen vote_li_b = vote_li_MA_b
replace vote_li_b = vote_li_EB_b if surveyname == "EB2"
label var vote_li_b "Liberals"

gen vote_gr_MA_b = (vote_gr_MA - 0.1527)
gen vote_gr_EB_b = (vote_gr_EB - 0.1527)

gen vote_gr_b = vote_gr_MA_b
replace vote_gr_b = vote_gr_EB_b if surveyname == "EB2"
label var vote_gr_b "Greens"

gen vote_rl_MA_b = (vote_rl_MA - 0.086)
gen vote_rl_EB_b = (vote_rl_EB - 0.086)

gen vote_rl_b = vote_rl_MA_b
replace vote_rl_b = vote_rl_EB_b if surveyname == "EB2"
label var vote_rl_b "Radical left"

gen vote_other_MA_b = (vote_other_MA - 0.0485)
gen vote_other_EB_b = (vote_other_EB - 0.0485)

gen vote_other_b = vote_other_MA_b
replace vote_other_b = vote_other_EB_b if surveyname == "EB2"
label var vote_other_b "Other"

sort surveyname
by surveyname: ci means vote_other_b vote_gr_b vote_li_b vote_so_b vote_cd_b vote_vb_b vote_nva_b vote_rl_b

***Plot it, baby 

gen surveyname1=1
replace surveyname1 = 2 if surveyname == "EB2"

foreach var of varlist turnout_b vote_nva_b vote_cd_b vote_so_b vote_li_b vote_gr_b vote_vb_b vote_rl_b vote_other_b {
     mean `var' if surveyname1==1
     estimates store maple_`var'
     mean `var' if surveyname1==2
     estimates store eb_`var'
    
 }

estimates dir

coefplot (maple*, label(Online)) (eb*, label(EB)) ///
 , drop(_cons) xline(0) title("Belgium")

est clear

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\belgium_vote.dta", replace


***Germany

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\germany.dta"

order country surveyname id 
keep if surveyname == "EB2" | surveyname == "MAPLE2"

keep country surveyname id voted_eu_EB party_voted_eu_EB voted_eu_MA votechoice_eu_MA

*Turnout

gen turnout_MA = .
replace turnout_MA = 0 if voted_eu_MA > 1 & voted_eu_MA != .
replace turnout_MA = 1 if voted_eu_MA == 1

gen turnout_EB = .
replace turnout_EB = 0 if voted_eu_EB > 1 & voted_eu_EB != .
replace turnout_EB = 1 if voted_eu_EB == 1

gen turnout_MA_b = (turnout_MA - 0.6138)
gen turnout_EB_b = (turnout_EB - 0.6138)

gen turnout_b = turnout_MA_b
replace turnout_b = turnout_EB_b if surveyname == "EB2"
label var turnout_b "Turnout"

sort surveyname
by surveyname: ci means turnout_b

***Parties

*Maple

gen vote_valid_MA = .
replace vote_valid_MA = 0 if votechoice_eu_MA <= 66

gen vote_cdu_MA = vote_valid_MA
replace vote_cdu_MA = 1 if votechoice_eu_MA == 2

gen vote_spd_MA = vote_valid_MA
replace vote_spd_MA = 1 if votechoice_eu_MA == 8

gen vote_gr_MA = vote_valid_MA
replace vote_gr_MA = 1 if votechoice_eu_MA == 3 

gen vote_afd_MA = vote_valid_MA
replace vote_afd_MA = 1 if votechoice_eu_MA == 1 

gen vote_fdp_MA = vote_valid_MA
replace vote_fdp_MA = 1 if votechoice_eu_MA == 9 

gen vote_li_MA = vote_valid_MA
replace vote_li_MA = 1 if votechoice_eu_MA == 4 

gen vote_other_MA = vote_valid_MA
replace vote_other_MA = 1 if votechoice_eu_MA == 5 | votechoice_eu_MA == 6 | votechoice_eu_MA == 7 | votechoice_eu_MA == 10 | votechoice_eu_MA == 11 | votechoice_eu_MA == 12 | votechoice_eu_MA == 66

*EB

gen vote_valid_EB = .
replace vote_valid_EB = 0 if party_voted_eu_EB <= 17

rename party_voted_eu_EB votechoice_eu_EB

gen vote_cdu_EB = vote_valid_EB
replace vote_cdu_EB = 1 if votechoice_eu_EB == 1

gen vote_spd_EB = vote_valid_EB
replace vote_spd_EB = 1 if votechoice_eu_EB == 2

gen vote_gr_EB = vote_valid_EB
replace vote_gr_EB = 1 if votechoice_eu_EB == 3 

gen vote_afd_EB = vote_valid_EB
replace vote_afd_EB = 1 if votechoice_eu_EB == 7 

gen vote_fdp_EB = vote_valid_EB
replace vote_fdp_EB = 1 if votechoice_eu_EB == 5 

gen vote_li_EB = vote_valid_EB
replace vote_li_EB = 1 if votechoice_eu_EB == 4 

gen vote_other_EB = vote_valid_EB
replace vote_other_EB = 1 if votechoice_eu_EB == 6 | votechoice_eu_EB == 8 | votechoice_eu_EB == 9 | votechoice_eu_EB == 10 | votechoice_eu_EB == 11 | votechoice_eu_EB == 12 | votechoice_eu_EB == 13 | votechoice_eu_EB == 14 | votechoice_eu_EB == 16


*Merge parties

gen vote_cdu_MA_b = (vote_cdu_MA - 0.289)
gen vote_cdu_EB_b = (vote_cdu_EB - 0.289)

gen vote_cdu_b = vote_cdu_MA_b
replace vote_cdu_b = vote_cdu_EB_b if surveyname == "EB2"
label var vote_cdu_b "CDU/CSU"

gen vote_spd_MA_b = (vote_spd_MA - 0.158)
gen vote_spd_EB_b = (vote_spd_EB - 0.158)

gen vote_spd_b = vote_spd_MA_b
replace vote_spd_b = vote_spd_EB_b if surveyname == "EB2"
label var vote_spd_b "SPD"

gen vote_gr_MA_b = (vote_gr_MA - 0.205)
gen vote_gr_EB_b = (vote_gr_EB - 0.205)

gen vote_gr_b = vote_gr_MA_b
replace vote_gr_b = vote_gr_EB_b if surveyname == "EB2"
label var vote_gr_b "Greens"

gen vote_afd_MA_b = (vote_afd_MA - 0.11)
gen vote_afd_EB_b = (vote_afd_EB - 0.11)

gen vote_afd_b = vote_afd_MA_b
replace vote_afd_b = vote_afd_EB_b if surveyname == "EB2"
label var vote_afd_b "AfD"

gen vote_li_MA_b = (vote_li_MA - 0.055)
gen vote_li_EB_b = (vote_li_EB - 0.055)

gen vote_li_b = vote_li_MA_b
replace vote_li_b = vote_li_EB_b if surveyname == "EB2"
label var vote_li_b "Linke"

gen vote_fdp_MA_b = (vote_fdp_MA - 0.054)
gen vote_fdp_EB_b = (vote_fdp_EB - 0.054)

gen vote_fdp_b = vote_fdp_MA_b
replace vote_fdp_b = vote_fdp_EB_b if surveyname == "EB2"
label var vote_fdp_b "FDP"

gen vote_other_MA_b = (vote_other_MA - 0.129)
gen vote_other_EB_b = (vote_other_EB - 0.129)

gen vote_other_b = vote_other_MA_b
replace vote_other_b = vote_other_EB_b if surveyname == "EB2"
label var vote_other_b "Other"

sort surveyname
by surveyname: ci means vote_cdu_b vote_spd_b vote_gr_b vote_afd_b vote_li_b vote_fdp_b vote_other_b

***Plot it, baby 

gen surveyname1=1
replace surveyname1 = 2 if surveyname == "EB2"

foreach var of varlist turnout_b vote_cdu_b vote_spd_b vote_gr_b vote_afd_b vote_li_b vote_fdp_b vote_other_b {
     mean `var' if surveyname1==1
     estimates store maple_`var'
     mean `var' if surveyname1==2
     estimates store eb_`var'
    
 }

estimates dir

coefplot (maple*, label(Online)) (eb*, label(EB)) ///
 , drop(_cons) xline(0) title("Germany")

est clear

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\germany_vote.dta", replace

***Greece

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\greece.dta"

order country surveyname id 
keep if surveyname == "EB2" | surveyname == "MAPLE2"

keep country surveyname id voted_eu_EB party_voted_eu_EB voted_eu_MA votechoice_eu_MA

*Turnout

gen turnout_MA = .
replace turnout_MA = 0 if voted_eu_MA > 1 & voted_eu_MA != .
replace turnout_MA = 1 if voted_eu_MA == 1

gen turnout_EB = .
replace turnout_EB = 0 if voted_eu_EB > 1 & voted_eu_EB != .
replace turnout_EB = 1 if voted_eu_EB == 1

gen turnout_MA_b = (turnout_MA - 0.5869)
gen turnout_EB_b = (turnout_EB - 0.5869)

gen turnout_b = turnout_MA_b
replace turnout_b = turnout_EB_b if surveyname == "EB2"
label var turnout_b "Turnout"

sort surveyname
by surveyname: ci means turnout_b

***Parties

*Maple

gen vote_valid_MA = .
replace vote_valid_MA = 0 if votechoice_eu_MA <= 66

gen vote_nd_MA = vote_valid_MA
replace vote_nd_MA = 1 if votechoice_eu_MA == 5

gen vote_sy_MA = vote_valid_MA
replace vote_sy_MA = 1 if votechoice_eu_MA == 9

gen vote_ki_MA = vote_valid_MA
replace vote_ki_MA = 1 if votechoice_eu_MA == 4 

gen vote_kke_MA = vote_valid_MA
replace vote_kke_MA = 1 if votechoice_eu_MA == 2 

gen vote_xa_MA = vote_valid_MA
replace vote_xa_MA = 1 if votechoice_eu_MA == 3 

gen vote_ea_MA = vote_valid_MA
replace vote_ea_MA = 1 if votechoice_eu_MA == 7 

gen vote_me_MA = vote_valid_MA
replace vote_me_MA = 1 if votechoice_eu_MA == 12

gen vote_other_MA = vote_valid_MA
replace vote_other_MA = 1 if votechoice_eu_MA == 1 | votechoice_eu_MA == 6 | votechoice_eu_MA == 8 | votechoice_eu_MA == 10 | votechoice_eu_MA == 11 | votechoice_eu_MA == 13 | votechoice_eu_MA == 66

*EB

gen vote_valid_EB = .
replace vote_valid_EB = 0 if party_voted_eu_EB <= 17

rename party_voted_eu_EB votechoice_eu_EB

gen vote_nd_EB = vote_valid_EB
replace vote_nd_EB = 1 if votechoice_eu_EB == 1

gen vote_sy_EB = vote_valid_EB
replace vote_sy_EB = 1 if votechoice_eu_EB == 2

gen vote_ki_EB = vote_valid_EB
replace vote_ki_EB = 1 if votechoice_eu_EB == 3 

gen vote_kke_EB = vote_valid_EB
replace vote_kke_EB = 1 if votechoice_eu_EB == 5 

gen vote_xa_EB = vote_valid_EB
replace vote_xa_EB = 1 if votechoice_eu_EB == 4 

gen vote_ea_EB = vote_valid_EB
replace vote_ea_EB = 1 if votechoice_eu_EB == 11 

gen vote_me_EB = vote_valid_EB
replace vote_me_EB = 1 if votechoice_eu_EB == 13

gen vote_other_EB = vote_valid_EB
replace vote_other_EB = 1 if votechoice_eu_EB == 6 | votechoice_eu_EB == 7 | votechoice_eu_EB == 9 | votechoice_eu_EB == 10 | votechoice_eu_EB == 12 | votechoice_eu_EB == 14 | votechoice_eu_EB == 17


*Merge parties

gen vote_nd_MA_b = (vote_nd_MA - 0.3312)
gen vote_nd_EB_b = (vote_nd_EB - 0.3312)

gen vote_nd_b = vote_nd_MA_b
replace vote_nd_b = vote_nd_EB_b if surveyname == "EB2"
label var vote_nd_b "ND"

gen vote_sy_MA_b = (vote_sy_MA - 0.2375)
gen vote_sy_EB_b = (vote_sy_EB - 0.2375)

gen vote_sy_b = vote_sy_MA_b
replace vote_sy_b = vote_sy_EB_b if surveyname == "EB2"
label var vote_sy_b "SYRIZA"

gen vote_ki_MA_b = (vote_ki_MA - 0.0772)
gen vote_ki_EB_b = (vote_ki_EB - 0.0772)

gen vote_ki_b = vote_ki_MA_b
replace vote_ki_b = vote_ki_EB_b if surveyname == "EB2"
label var vote_ki_b "KINAL"

gen vote_kke_MA_b = (vote_kke_MA - 0.0535)
gen vote_kke_EB_b = (vote_kke_EB - 0.0535)

gen vote_kke_b = vote_kke_MA_b
replace vote_kke_b = vote_kke_EB_b if surveyname == "EB2"
label var vote_kke_b "KKE"

gen vote_xa_MA_b = (vote_xa_MA - 0.0487)
gen vote_xa_EB_b = (vote_xa_EB - 0.0487)

gen vote_xa_b = vote_xa_MA_b
replace vote_xa_b = vote_xa_EB_b if surveyname == "EB2"
label var vote_xa_b "XA"

gen vote_ea_MA_b = (vote_ea_MA - 0.0418)
gen vote_ea_EB_b = (vote_ea_EB - 0.0418)

gen vote_ea_b = vote_ea_MA_b
replace vote_ea_b = vote_ea_EB_b if surveyname == "EB2"
label var vote_ea_b "EL"

gen vote_me_MA_b = (vote_me_MA - 0.0299)
gen vote_me_EB_b = (vote_me_EB - 0.0299)

gen vote_me_b = vote_ea_MA_b
replace vote_me_b = vote_me_EB_b if surveyname == "EB2"
label var vote_me_b "MERA25"

gen vote_other_MA_b = (vote_other_MA - 0.1802)
gen vote_other_EB_b = (vote_other_EB - 0.1802)

gen vote_other_b = vote_other_MA_b
replace vote_other_b = vote_other_EB_b if surveyname == "EB2"
label var vote_other_b "Other"

sort surveyname
by surveyname: ci means turnout_b vote_nd_b vote_sy_b vote_ki_b vote_kke_b vote_xa_b vote_ea_b vote_me_b vote_other_b

***Plot it, baby 

gen surveyname1=1
replace surveyname1 = 2 if surveyname == "EB2"

foreach var of varlist turnout_b vote_nd_b vote_sy_b vote_ki_b vote_kke_b vote_xa_b vote_ea_b vote_me_b vote_other_b {
     mean `var' if surveyname1==1
     estimates store maple_`var'
     mean `var' if surveyname1==2
     estimates store eb_`var'
    
 }

estimates dir

coefplot (maple*, label(Online)) (eb*, label(EB)) ///
 , drop(_cons) xline(0) title("Greece")

est clear

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\greece_vote.dta", replace

***Ireland

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\ireland.dta"

order country surveyname id 
keep if surveyname == "EB2" | surveyname == "MAPLE2"

keep country surveyname id voted_eu_EB party_voted_eu_EB voted_eu_MA votechoice_eu_MA

*Turnout

gen turnout_MA = .
replace turnout_MA = 0 if voted_eu_MA > 1 & voted_eu_MA != .
replace turnout_MA = 1 if voted_eu_MA == 1

gen turnout_EB = .
replace turnout_EB = 0 if voted_eu_EB > 1 & voted_eu_EB != .
replace turnout_EB = 1 if voted_eu_EB == 1

gen turnout_MA_b = (turnout_MA - 0.497)
gen turnout_EB_b = (turnout_EB - 0.497)

gen turnout_b = turnout_MA_b
replace turnout_b = turnout_EB_b if surveyname == "EB2"
label var turnout_b "Turnout"

sort surveyname
by surveyname: ci means turnout_b

***Parties

*Maple

gen vote_valid_MA = .
replace vote_valid_MA = 0 if votechoice_eu_MA <= 66

gen vote_fg_MA = vote_valid_MA
replace vote_fg_MA = 1 if votechoice_eu_MA == 2

gen vote_ff_MA = vote_valid_MA
replace vote_ff_MA = 1 if votechoice_eu_MA == 1

gen vote_ind_MA = vote_valid_MA
replace vote_ind_MA = 1 if votechoice_eu_MA == 8 |  votechoice_eu_MA == 9 | votechoice_eu_MA == 10 

gen vote_sf_MA = vote_valid_MA
replace vote_sf_MA = 1 if votechoice_eu_MA == 4 

gen vote_gp_MA = vote_valid_MA
replace vote_gp_MA = 1 if votechoice_eu_MA == 5  

gen vote_la_MA = vote_valid_MA
replace vote_la_MA = 1 if votechoice_eu_MA == 3

gen vote_other_MA = vote_valid_MA
replace vote_other_MA = 1 if votechoice_eu_MA == 6 | votechoice_eu_MA == 7 | votechoice_eu_MA == 11 | votechoice_eu_MA == 66

*EB

gen vote_valid_EB = .
replace vote_valid_EB = 0 if party_voted_eu_EB <= 17

rename party_voted_eu_EB votechoice_eu_EB

gen vote_fg_EB = vote_valid_EB
replace vote_fg_EB = 1 if votechoice_eu_EB == 1

gen vote_ff_EB = vote_valid_EB
replace vote_ff_EB = 1 if votechoice_eu_EB == 2

gen vote_ind_EB = vote_valid_EB
replace vote_ind_EB = 1 if votechoice_eu_EB == 5 

gen vote_sf_EB = vote_valid_EB
replace vote_sf_EB = 1 if votechoice_eu_EB == 3 

gen vote_gp_EB = vote_valid_EB
replace vote_gp_EB = 1 if votechoice_eu_EB == 7 

gen vote_la_EB = vote_valid_EB
replace vote_la_EB = 1 if votechoice_eu_EB == 4

gen vote_other_EB = vote_valid_EB
replace vote_other_EB = 1 if votechoice_eu_EB == 6 | votechoice_eu_EB == 8


*Merge parties

gen vote_fg_MA_b = (vote_fg_MA - 0.2959)
gen vote_fg_EB_b = (vote_fg_EB - 0.2959)

gen vote_fg_b = vote_fg_MA_b
replace vote_fg_b = vote_fg_EB_b if surveyname == "EB2"
label var vote_fg_b "Fine Gael"

gen vote_ff_MA_b = (vote_ff_MA - 0.1655)
gen vote_ff_EB_b = (vote_ff_EB - 0.1655)

gen vote_ff_b = vote_ff_MA_b
replace vote_ff_b = vote_ff_EB_b if surveyname == "EB2"
label var vote_ff_b "Fianna Fáil"

gen vote_ind_MA_b = (vote_ind_MA - 0.2313)
gen vote_ind_EB_b = (vote_ind_EB - 0.2313)

gen vote_ind_b = vote_ind_MA_b
replace vote_ind_b = vote_ind_EB_b if surveyname == "EB2"
label var vote_ind_b "Independents"

gen vote_sf_MA_b = (vote_sf_MA - 0.1168)
gen vote_sf_EB_b = (vote_sf_EB - 0.1168)

gen vote_sf_b = vote_sf_MA_b
replace vote_sf_b = vote_sf_EB_b if surveyname == "EB2"
label var vote_sf_b "Sinn Féin"

gen vote_gp_MA_b = (vote_gp_MA - 0.1137)
gen vote_gp_EB_b = (vote_gp_EB - 0.1137)

gen vote_gp_b = vote_gp_MA_b
replace vote_gp_b = vote_gp_EB_b if surveyname == "EB2"
label var vote_gp_b "Greens"

gen vote_la_MA_b = (vote_la_MA - 0.0314)
gen vote_la_EB_b = (vote_la_EB - 0.0314)

gen vote_la_b = vote_la_MA_b
replace vote_la_b = vote_la_EB_b if surveyname == "EB2"
label var vote_la_b "Labour"

gen vote_other_MA_b = (vote_other_MA - 0.0454)
gen vote_other_EB_b = (vote_other_EB - 0.0454)

gen vote_other_b = vote_other_MA_b
replace vote_other_b = vote_other_EB_b if surveyname == "EB2"
label var vote_other_b "Other"

sort surveyname
by surveyname: ci means turnout_b vote_fg_b vote_ff_b vote_ind_b vote_sf_b vote_gp_b vote_la_b vote_other_b

***Plot it, baby 

gen surveyname1=1
replace surveyname1 = 2 if surveyname == "EB2"

foreach var of varlist turnout_b vote_fg_b vote_ff_b vote_ind_b vote_sf_b vote_gp_b vote_la_b vote_other_b {
     mean `var' if surveyname1==1
     estimates store maple_`var'
     mean `var' if surveyname1==2
     estimates store eb_`var'
    
 }

estimates dir

coefplot (maple*, label(Online)) (eb*, label(EB)) ///
 , drop(_cons) xline(0) title("Ireland")

est clear

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\ireland_vote.dta", replace

***Portugal

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\portugal.dta"

order country surveyname id 
keep if surveyname == "EB2" | surveyname == "MAPLE2"

keep country surveyname id voted_eu_EB party_voted_eu_EB voted_eu_MA votechoice_eu_MA

*Turnout

gen turnout_MA = .
replace turnout_MA = 0 if voted_eu_MA > 1 & voted_eu_MA != .
replace turnout_MA = 1 if voted_eu_MA == 1

gen turnout_EB = .
replace turnout_EB = 0 if voted_eu_EB > 1 & voted_eu_EB != .
replace turnout_EB = 1 if voted_eu_EB == 1

gen turnout_MA_b = (turnout_MA - 0.3075)
gen turnout_EB_b = (turnout_EB - 0.3075)

gen turnout_b = turnout_MA_b
replace turnout_b = turnout_EB_b if surveyname == "EB2"
label var turnout_b "Turnout"

sort surveyname
by surveyname: ci means turnout_b

***Parties

*Maple

gen vote_valid_MA = .
replace vote_valid_MA = 0 if votechoice_eu_MA <= 66

gen vote_ps_MA = vote_valid_MA
replace vote_ps_MA = 1 if votechoice_eu_MA == 9

gen vote_psd_MA = vote_valid_MA
replace vote_psd_MA = 1 if votechoice_eu_MA == 5

gen vote_be_MA = vote_valid_MA
replace vote_be_MA = 1 if votechoice_eu_MA == 1 

gen vote_cdu_MA = vote_valid_MA
replace vote_cdu_MA = 1 if votechoice_eu_MA == 2 

gen vote_cds_MA = vote_valid_MA
replace vote_cds_MA = 1 if votechoice_eu_MA == 4  

gen vote_pan_MA = vote_valid_MA
replace vote_pan_MA = 1 if votechoice_eu_MA == 8

gen vote_other_MA = vote_valid_MA
replace vote_other_MA = 1 if votechoice_eu_MA == 3 | votechoice_eu_MA == 6 | votechoice_eu_MA == 7 | votechoice_eu_MA == 10 | votechoice_eu_MA == 11 | votechoice_eu_MA == 66

*EB

gen vote_valid_EB = .
replace vote_valid_EB = 0 if party_voted_eu_EB <= 17

rename party_voted_eu_EB votechoice_eu_EB

gen vote_ps_EB = vote_valid_EB
replace vote_ps_EB = 1 if votechoice_eu_EB == 1

gen vote_psd_EB = vote_valid_EB
replace vote_psd_EB = 1 if votechoice_eu_EB == 2

gen vote_be_EB = vote_valid_EB
replace vote_be_EB = 1 if votechoice_eu_EB == 3 

gen vote_cdu_EB = vote_valid_EB
replace vote_cdu_EB = 1 if votechoice_eu_EB == 4 

gen vote_cds_EB = vote_valid_EB
replace vote_cds_EB = 1 if votechoice_eu_EB == 5  

gen vote_pan_EB = vote_valid_EB
replace vote_pan_EB = 1 if votechoice_eu_EB == 6

gen vote_other_EB = vote_valid_EB
replace vote_other_EB = 1 if votechoice_eu_EB == 7 | votechoice_eu_EB == 8 | votechoice_eu_EB == 10 | votechoice_eu_EB == 11 | votechoice_eu_EB == 12 


*Merge parties

gen vote_ps_MA_b = (vote_ps_MA - 0.3588)
gen vote_ps_EB_b = (vote_ps_EB - 0.3588)

gen vote_ps_b = vote_ps_MA_b
replace vote_ps_b = vote_ps_EB_b if surveyname == "EB2"
label var vote_ps_b "PS"

gen vote_psd_MA_b = (vote_psd_MA - 0.2356)
gen vote_psd_EB_b = (vote_psd_EB - 0.2356)

gen vote_psd_b = vote_psd_MA_b
replace vote_psd_b = vote_psd_EB_b if surveyname == "EB2"
label var vote_psd_b "PSD"

gen vote_be_MA_b = (vote_be_MA - 0.1056)
gen vote_be_EB_b = (vote_be_EB - 0.1056)

gen vote_be_b = vote_be_MA_b
replace vote_be_b = vote_be_EB_b if surveyname == "EB2"
label var vote_be_b "BE"

gen vote_cdu_MA_b = (vote_cdu_MA - 0.0741)
gen vote_cdu_EB_b = (vote_cdu_EB - 0.0741)

gen vote_cdu_b = vote_cdu_MA_b
replace vote_cdu_b = vote_cdu_EB_b if surveyname == "EB2"
label var vote_cdu_b "CDU"

gen vote_cds_MA_b = (vote_cds_MA - 0.0665)
gen vote_cds_EB_b = (vote_cds_EB - 0.0665)

gen vote_cds_b = vote_cds_MA_b
replace vote_cds_b = vote_cds_EB_b if surveyname == "EB2"
label var vote_cds_b "CDS-PP"

gen vote_pan_MA_b = (vote_pan_MA - 0.0546)
gen vote_pan_EB_b = (vote_pan_EB - 0.0546)

gen vote_pan_b = vote_pan_MA_b
replace vote_pan_b = vote_pan_EB_b if surveyname == "EB2"
label var vote_pan_b "PAN"

gen vote_other_MA_b = (vote_other_MA - 0.1048)
gen vote_other_EB_b = (vote_other_EB - 0.1048)

gen vote_other_b = vote_other_MA_b
replace vote_other_b = vote_other_EB_b if surveyname == "EB2"
label var vote_other_b "Other"

sort surveyname
by surveyname: ci means turnout_b vote_ps_b vote_psd_b vote_be_b vote_cdu_b vote_cds_b vote_pan_b vote_other_b

***Plot it, baby 

gen surveyname1=1
replace surveyname1 = 2 if surveyname == "EB2"

foreach var of varlist turnout_b vote_ps_b vote_psd_b vote_be_b vote_cdu_b vote_cds_b vote_pan_b vote_other_b {
     mean `var' if surveyname1==1
     estimates store maple_`var'
     mean `var' if surveyname1==2
     estimates store eb_`var'
    
 }

estimates dir

coefplot (maple*, label(Online)) (eb*, label(EB)) ///
 , drop(_cons) xline(0) title("Portugal")

est clear

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\portugal_vote.dta", replace

***Spain

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\spain.dta"

order country surveyname id 
keep if surveyname == "EB2" | surveyname == "MAPLE2"

keep country surveyname id voted_eu_EB party_voted_eu_EB voted_eu_MA votechoice_eu_MA

*Turnout

gen turnout_MA = .
replace turnout_MA = 0 if voted_eu_MA > 1 & voted_eu_MA != .
replace turnout_MA = 1 if voted_eu_MA == 1

gen turnout_EB = .
replace turnout_EB = 0 if voted_eu_EB > 1 & voted_eu_EB != .
replace turnout_EB = 1 if voted_eu_EB == 1

gen turnout_MA_b = (turnout_MA - 0.6073)
gen turnout_EB_b = (turnout_EB - 0.6073)

gen turnout_b = turnout_MA_b
replace turnout_b = turnout_EB_b if surveyname == "EB2"
label var turnout_b "Turnout"

sort surveyname
by surveyname: ci means turnout_b

***Parties

*Maple

gen vote_valid_MA = .
replace vote_valid_MA = 0 if votechoice_eu_MA <= 66

gen vote_ps_MA = vote_valid_MA
replace vote_ps_MA = 1 if votechoice_eu_MA == 2

gen vote_pp_MA = vote_valid_MA
replace vote_pp_MA = 1 if votechoice_eu_MA == 4

gen vote_cs_MA = vote_valid_MA
replace vote_cs_MA = 1 if votechoice_eu_MA == 1 

gen vote_po_MA = vote_valid_MA
replace vote_po_MA = 1 if votechoice_eu_MA == 5 

gen vote_vox_MA = vote_valid_MA
replace vote_vox_MA = 1 if votechoice_eu_MA == 10  

gen vote_other_MA = vote_valid_MA
replace vote_other_MA = 1 if votechoice_eu_MA == 3 | votechoice_eu_MA == 6 | votechoice_eu_MA == 7 | votechoice_eu_MA == 8 | votechoice_eu_MA == 9 | votechoice_eu_MA == 11 | votechoice_eu_MA == 66

*EB

gen vote_valid_EB = .
replace vote_valid_EB = 0 if party_voted_eu_EB <= 17

rename party_voted_eu_EB votechoice_eu_EB

gen vote_ps_EB = vote_valid_EB
replace vote_ps_EB = 1 if votechoice_eu_EB == 3

gen vote_pp_EB = vote_valid_EB
replace vote_pp_EB = 1 if votechoice_eu_EB == 2

gen vote_cs_EB = vote_valid_EB
replace vote_cs_EB = 1 if votechoice_eu_EB == 1 

gen vote_po_EB = vote_valid_EB
replace vote_po_EB = 1 if votechoice_eu_EB == 4 

gen vote_vox_EB = vote_valid_EB
replace vote_vox_EB = 1 if votechoice_eu_EB == 10  

gen vote_other_EB = vote_valid_EB
replace vote_other_EB = 1 if votechoice_eu_EB == 5 | votechoice_eu_EB == 6 | votechoice_eu_EB == 7 | votechoice_eu_EB == 8 | votechoice_eu_EB == 9 | votechoice_eu_EB == 17


*Merge parties

gen vote_ps_MA_b = (vote_ps_MA - 0.3318)
gen vote_ps_EB_b = (vote_ps_EB - 0.3318)

gen vote_ps_b = vote_ps_MA_b
replace vote_ps_b = vote_ps_EB_b if surveyname == "EB2"
label var vote_ps_b "PSOE"

gen vote_pp_MA_b = (vote_pp_MA - 0.2035)
gen vote_pp_EB_b = (vote_pp_EB - 0.2035)

gen vote_pp_b = vote_pp_MA_b
replace vote_pp_b = vote_pp_EB_b if surveyname == "EB2"
label var vote_pp_b "PP"

gen vote_cs_MA_b = (vote_cs_MA - 0.123)
gen vote_cs_EB_b = (vote_cs_EB - 0.123)

gen vote_cs_b = vote_cs_MA_b
replace vote_cs_b = vote_cs_EB_b if surveyname == "EB2"
label var vote_cs_b "Ciudadanos"

gen vote_po_MA_b = (vote_po_MA - 0.1017)
gen vote_po_EB_b = (vote_po_EB - 0.1017)

gen vote_po_b = vote_po_MA_b
replace vote_po_b = vote_po_EB_b if surveyname == "EB2"
label var vote_po_b "Unidas Podemos"

gen vote_vox_MA_b = (vote_vox_MA - 0.0628)
gen vote_vox_EB_b = (vote_vox_EB - 0.0628)

gen vote_vox_b = vote_vox_MA_b
replace vote_vox_b = vote_vox_EB_b if surveyname == "EB2"
label var vote_vox_b "VOX"

gen vote_other_MA_b = (vote_other_MA - 0.1772)
gen vote_other_EB_b = (vote_other_EB - 0.1772)

gen vote_other_b = vote_other_MA_b
replace vote_other_b = vote_other_EB_b if surveyname == "EB2"
label var vote_other_b "Other"

sort surveyname
by surveyname: ci means turnout_b vote_ps_b vote_pp_b vote_cs_b vote_po_b vote_vox_b vote_other_b

***Plot it, baby 

gen surveyname1=1
replace surveyname1 = 2 if surveyname == "EB2"

foreach var of varlist turnout_b vote_ps_b vote_pp_b vote_cs_b vote_po_b vote_vox_b vote_other_b {
     mean `var' if surveyname1==1
     estimates store maple_`var'
     mean `var' if surveyname1==2
     estimates store eb_`var'
    
 }

estimates dir

coefplot (maple*, label(Online)) (eb*, label(EB)) ///
 , drop(_cons) xline(0) title("Spain")

est clear

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\spain_vote.dta", replace

***Tables

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\belgium_vote.dta"

format turnout_MA vote_nva_MA vote_cd_MA vote_so_MA vote_li_MA vote_gr_MA vote_vb_MA vote_rl_MA vote_other_MA %9.3f
format turnout_EB vote_nva_EB vote_cd_EB vote_so_EB vote_li_EB vote_gr_EB vote_vb_EB vote_rl_EB vote_other_EB %9.3f

ci means turnout_MA vote_nva_MA vote_cd_MA vote_so_MA vote_li_MA vote_gr_MA vote_vb_MA vote_rl_MA vote_other_MA
ci means turnout_EB vote_nva_EB vote_cd_EB vote_so_EB vote_li_EB vote_gr_EB vote_vb_EB vote_rl_EB vote_other_EB

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\belgium_vote.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\germany_vote.dta"

format turnout_MA vote_cdu_MA vote_spd_MA vote_gr_MA vote_afd_MA vote_fdp_MA vote_li_MA vote_other_MA %9.3f
format turnout_EB vote_cdu_EB vote_spd_EB vote_gr_EB vote_afd_EB vote_fdp_EB vote_li_EB vote_other_EB %9.3f

ci means turnout_MA vote_cdu_MA vote_spd_MA vote_gr_MA vote_afd_MA vote_fdp_MA vote_li_MA vote_other_MA
ci means turnout_EB vote_cdu_EB vote_spd_EB vote_gr_EB vote_afd_EB vote_fdp_EB vote_li_EB vote_other_EB

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\germany_vote.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\greece_vote.dta"

format turnout_MA vote_nd_MA vote_sy_MA vote_ki_MA vote_kke_MA vote_xa_MA vote_ea_MA vote_me_MA vote_other_MA %9.3f
format turnout_EB vote_nd_EB vote_sy_EB vote_ki_EB vote_kke_EB vote_xa_EB vote_ea_EB vote_me_EB vote_other_EB %9.3f

ci means turnout_MA vote_nd_MA vote_sy_MA vote_ki_MA vote_kke_MA vote_xa_MA vote_ea_MA vote_me_MA vote_other_MA
ci means turnout_EB vote_nd_EB vote_sy_EB vote_ki_EB vote_kke_EB vote_xa_EB vote_ea_EB vote_me_EB vote_other_EB

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\greece_vote.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\ireland_vote.dta"

format turnout_MA vote_fg_MA vote_ff_MA vote_ind_MA vote_sf_MA vote_gp_MA vote_la_MA vote_other_MA %9.3f
format turnout_EB vote_fg_EB vote_ff_EB vote_ind_EB vote_sf_EB vote_gp_EB vote_la_EB vote_other_EB %9.3f

ci means turnout_MA vote_fg_MA vote_ff_MA vote_ind_MA vote_sf_MA vote_gp_MA vote_la_MA vote_other_MA
ci means turnout_EB vote_fg_EB vote_ff_EB vote_ind_EB vote_sf_EB vote_gp_EB vote_la_EB vote_other_EB

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\ireland_vote.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\portugal_vote.dta"

format turnout_MA vote_ps_MA vote_psd_MA vote_be_MA vote_cdu_MA vote_cds_MA vote_pan_MA vote_other_MA %9.3f
format turnout_EB vote_ps_EB vote_psd_EB vote_be_EB vote_cdu_EB vote_cds_EB vote_pan_EB vote_other_EB %9.3f

ci means turnout_MA vote_ps_MA vote_psd_MA vote_be_MA vote_cdu_MA vote_cds_MA vote_pan_MA vote_other_MA
ci means turnout_EB vote_ps_EB vote_psd_EB vote_be_EB vote_cdu_EB vote_cds_EB vote_pan_EB vote_other_EB

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\portugal_vote.dta", replace

use "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\spain_vote.dta"

format turnout_MA vote_ps_MA vote_pp_MA vote_cs_MA vote_po_MA vote_vox_MA vote_other_MA %9.3f
format turnout_EB vote_ps_EB vote_pp_EB vote_cs_EB vote_po_EB vote_vox_EB vote_other_EB %9.3f

ci means turnout_MA vote_ps_MA vote_pp_MA vote_cs_MA vote_po_MA vote_vox_MA vote_other_MA
ci means turnout_EB vote_ps_EB vote_pp_EB vote_cs_EB vote_po_EB vote_vox_EB vote_other_EB

save "C:\Users\Administrator\Desktop\MAPLE\DATA\Analysis\new\spain_vote.dta", replace
